﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace Mota.EditModule
{
    public static class SqlDbTypeConverter
    {
        static public Type ToType(this SqlDbType dbType)
        {
            switch (dbType)
            {
                case SqlDbType.BigInt:
                    return typeof(System.Int64);
                case SqlDbType.Bit:
                    return typeof(System.Boolean);
                case SqlDbType.Char:
                case SqlDbType.VarChar:
                case SqlDbType.Text:
                case SqlDbType.NVarChar:
                case SqlDbType.NChar:
                case SqlDbType.NText:
                case SqlDbType.Xml:
                case SqlDbType.Structured:
                    return typeof(System.String);
                case SqlDbType.SmallDateTime:
                case SqlDbType.Date:
                case SqlDbType.DateTime:
                case SqlDbType.DateTime2:
                    return typeof(System.DateTime);
                case SqlDbType.DateTimeOffset:
                    return typeof(System.DateTimeOffset);
                case SqlDbType.Money:
                case SqlDbType.SmallMoney:
                case SqlDbType.Decimal:
                    return typeof(System.Decimal);
                case SqlDbType.Float:
                    return typeof(System.Double);
                case SqlDbType.Int:
                    return typeof(System.Int32);
                case SqlDbType.Real:
                    return typeof(System.Single);
                case SqlDbType.SmallInt:
                    return typeof(System.Int16);
                case SqlDbType.Time:
                    return typeof(System.TimeSpan);
                case SqlDbType.TinyInt:
                    return typeof(System.Byte);
                case SqlDbType.UniqueIdentifier:
                    return typeof(System.Guid);
                case SqlDbType.Image:
                case SqlDbType.Timestamp:
                case SqlDbType.Binary:
                case SqlDbType.VarBinary:
                    return typeof(System.Byte[]);
                default:
                    throw new InvalidCastException("Unknown type conversion " + dbType.ToString());
            }
        }

        
    }
}
